package com.lagou.filter;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.rpc.*;

@Activate(group={CommonConstants.CONSUMER})
public class TPMonitorFilter implements Filter {
    private final RemoteCallStatics statics = new RemoteCallStatics();

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

        String methodName = invocation.getMethodName();
        long startTime = System.currentTimeMillis();

        Result result = invoker.invoke(invocation);

        long endTime = System.currentTimeMillis();
        statics.collect(methodName, (endTime - startTime));

        return result;
    }
}
